package com.hx.localmiaosha.web;

import com.hx.common.api.MiaoshaGoodsService;
import com.hx.common.common.enums.ResultStatus;
import com.hx.common.exception.GlobleException;
import com.hx.localmiaosha.service.LocalMiaoshaGoodsService;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author wonghiu
 * @Date 2021/8/3 20:24
 * @Version 1.0.1
 *
 * 通过实现InitializingBean接口，在系统初始化时将秒杀商品上架
 */
@Component
public class initGoodsCache implements InitializingBean {
    @Autowired
    RedissonClient redissonClient;
    @Autowired
    LocalMiaoshaGoodsService goodsService;

    @Override
    public void afterPropertiesSet() throws Exception {

        try{
            goodsService.submitGoods2Cache();
        }catch (Exception e) {
            throw new GlobleException(ResultStatus.SUMBIT_GOODS_FAIL);
        }

    }
}
